package com.wisemoresystem.seal.action.seal.news;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_type;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.model.t_user;
import com.wisemoresystem.seal.service.SealNewService;
import com.wisemoresystem.seal.service.SealTypeConfigService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 新章申请 审核
 * 
 * @author 冯晓东
 *
 */
@Controller("sealNewsApplyCheck")
@Scope("prototype")
@RequestMapping("/ix/seal/news/apply/check")
public class SealNewsApplyCheckAction extends ProjBaseAction {

	@Autowired
	private SealNewService sealNewService;
	@Autowired
	private SealTypeConfigService sealTypeService;

	/**
	 * 新章复核
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = sealNewService
				.selectSealNewApplyCheckingList(srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/news/apply/check/list");
		mv.addObject("list", list);
		return mv;
	}

	/**
	 * 要复核的信息
	 * 
	 * @param seal_new_id
	 *            新章申请id
	 * @return
	 */
	@RequestMapping("/check_form")
	public ModelAndView check_form(String seal_new_id) {
		t_seal_new seal_new = oc.findObjById(seal_new_id, t_seal_new.class);
		// t_check check = oc.findObjById(seal_new.getCheck_id(),
		// t_check.class);

		t_bank bank = oc.findObjById(seal_new.getBank_id(), t_bank.class);
		t_user user = oc.findObjById(seal_new.getUser_id(), t_user.class);
		t_seal_type type = oc.findObjById(seal_new.getSeal_type_id(),
				t_seal_type.class);
		t_seal_type_config typeConfig = oc.findObjById(
				seal_new.getSeal_type_config_id(), t_seal_type_config.class);

		ModelAndView mv = new ModelAndView(
				"/jsp/seal/news/apply/check/check_form");
		mv.addObject("seal_new", seal_new);
		mv.addObject("bank", bank);
		mv.addObject("user", user);
		mv.addObject("type", type);
		mv.addObject("typeConfig", typeConfig);
		return mv;
	}

	/**
	 * 复核
	 * 
	 * @param seal_new_id
	 *            新章id
	 * @param flag
	 *            状态
	 * @param note
	 *            复核备注
	 * @return
	 */
	@RequestMapping("/check")
	public ModelAndView check(String seal_new_id, String flag, String note) {
		boolean isTop;
		t_bank bank = oc.findObjById(WebTools.getCurrentBankId(), t_bank.class);
		if ("5".equals(bank.getLevel_id())) {
			isTop = true;
		} else {
			isTop = false;
		}

		sealNewService.check(seal_new_id, flag, note, isTop);
		logT.logH("新章申请审核", t_seal_new.class, seal_new_id);
		this.setTipMsg("复核成功!");
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}